import { App } from 'vue'
import api from '@/api'
import mixin from '@/mixin'
import utils from '@/utils'
import '@/style/reset.css'
import '@/style/style.scss'

export default {
  install(app: App) {

    //全局混入
    app.mixin(mixin)

    //全局挂载接口
    app.config.globalProperties.$api = api;
    app.config.globalProperties.$utils = utils;

    const requireComponent = require.context('@/components/common', false, /Common[A-Z]\w+\.(vue|js)$/)
    requireComponent.keys().forEach(fileName => {
      // 获取组件配置
      const componentConfig = requireComponent(fileName)

      // 获取组件的 PascalCase 命名
      const componentName = fileName.split('/').pop()?.split('.').shift()

      // 全局注册组件
      app.component(<string>componentName, componentConfig.default || componentConfig)
    })


  }
}